
#pragma once

class CXXTEA
{
public:
	CXXTEA(LPCSTR k, bool freekeywhendestroy);
	CXXTEA(LPCSTR k, bool freekeywhendestroy, int a, int b, int c, int d);
	CXXTEA(LPCSTR k, bool freekeywhendestroy, LPCSTR zmStr);	//"5,2,3,4"
	CXXTEA(LPCSTR k, bool freekeywhendestroy, LPCWSTR zmStr);	//"5,2,3,4"
	~CXXTEA();

	byte* Encrypt(const byte * src, intptr_t srcLen, intptr_t &destLen);
	byte* Decrypt(const byte * src, intptr_t srcLen, intptr_t &destLen);

protected:
	DWORD* ToUInt32Array(const byte * src, int srcLen, bool IncludeLength,
		int *pDestLen = nullptr, int minLen = 0);
	byte* ToByteArray(const DWORD * src, int srcLen, bool IncludeLength, int *pDestLen = nullptr);
	bool btea(DWORD* v, int n, DWORD* k);

	int zm[4];
	LPCSTR key; bool freeKeyWhenDestroy;
	int keyLen;
};

extern CXXTEA msgTea;
